package com.yn.xgame.message;

import com.yn.xgame.IFunc2;
import com.yn.xgame.IRFunc2;
import com.yn.xgame.IServer;

public class SupplyAndConsumeMessage2<T1, T2, R> implements IFuncMessage {

	private IServer consumeServer;
	private T1 t1;
	private T2 t2;
	private IRFunc2<T1, T2, R> iRFunc;
	private IFunc2<T1, R> consumer;

	public SupplyAndConsumeMessage2(IServer consumeServer, T1 t1, T2 t2, IRFunc2<T1, T2, R> iRFunc,
			IFunc2<T1, R> consumer) {
		super();
		this.consumeServer = consumeServer;
		this.t1 = t1;
		this.t2 = t2;
		this.iRFunc = iRFunc;
		this.consumer = consumer;
	}

	@Override
	public void apply() {
		R r = iRFunc.call(t1, t2);
		consumeServer.pushMessage(new Func2Message<T1, R>(t1, r, consumer));
	}

}
